﻿using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

using Warehouse.Service.Data;
using Warehouse.Silverlight.Modules.Main.Models;
using Warehouse.Silverlight.Modules.Main.ViewModels;

namespace Warehouse.Silverlight.Modules.Main.Views
{
    [Export]
    [PartCreationPolicy(CreationPolicy.NonShared)]
    public partial class CategoryTreeView : UserControl
    {
        public CategoryTreeView()
        {
            InitializeComponent();
        }

        [Import]
        public CategoryTreeViewModel ViewModel
        {
            get { return this.DataContext as CategoryTreeViewModel; }
            set { this.DataContext = value; }
        }

        // UI Events
        private void treeView1_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
        {
            var item = (Category)e.NewValue;

            this.Dispatcher.BeginInvoke(() =>
            {
                ViewModel.SelectedItem = item;
            });
        }

    }
}
